<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="附件名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入附件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="附件类型" prop="type">
        <el-select
          v-model="queryParams.reportType"
          placeholder="请选择附件类型"
          clearable>
          <el-option
            v-for="dict in reportTypeList"
            :key="dict.key"
            :label="dict.label"
            :value="dict.key"/>
        </el-select>
      </el-form-item>
      <el-form-item label="报告日期">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置</el-button
        >
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="centerDialogVisible = true"
          v-hasPermi="['workOrder:OrderEnclosure:export']"
        >批量导出</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- 去除功能按钮 -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="OrderEnclosureList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="附件名称" align="center" prop="name" />
      <el-table-column label="报告日期" align="center" prop="reportTime" />
      <el-table-column label="报告类型" align="center" prop="reportType">
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.createTime, "{y}.{m}.{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文件路径" align="center" prop="url" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      :visible.sync="centerDialogVisible"
      width="30%"
      :center="true"
    >
      <!-- <span style="width: 100%;text-align: center;display: inline-block;">将根据当前筛选条件导出所有数据,是否继续?</span> -->
      <span style="width: 100%;text-align: center;display: inline-block;">将根据当前筛选条件导出所有附件数据,是否继续?</span>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="handleExport">
            确认
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import {listReportEnclosure} from "@/api/report/reportEnclosure"

  export default {
    name: "OrderEnclosure",
    dicts: ["enclosure_type"],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 工单附件表格数据
        OrderEnclosureList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 附件类型时间范围
        daterangeCreateTime: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: null,
          type: null,
          reportType:null
        },
        reportTypeList: [
                    {
                      key: '日报',
                      label: '日报'
                    },
                    {
                      key: '月报',
                      label: '月报'
                    },
                    {
                      key: '季报',
                      label: '季报'
                    }
        ],
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        centerDialogVisible: false
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询工单附件列表 */
      getList() {
        this.loading = true;
        listReportEnclosure(this.addDateRange(this.queryParams, this.daterangeCreateTime)).then((response) => {
          this.OrderEnclosureList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          workNumber: null,
          enclosureCode: null,
          name: null,
          url: null,
          type: null,
          createTime: null,
          createBy: null,
          updateTime: null,
          updateBy: null,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeCreateTime = [];
        this.resetForm("queryForm");
        this.queryParams.reportType=null
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map((item) => item.id);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      },
      /** 导出按钮操作 */
      handleExport() {
        this.centerDialogVisible = false
        this.downloadNew('/workOrder/report/exportEnclosure', {
          ...this.addDateRange(this.queryParams, this.daterangeCreateTime)
        }, `reportEnclosure_${new Date().getTime()}.rar`).then(res => {

        })
      },
    },
  };
</script>
<style scoped>
  .dialog-footer button:first-child {
    margin-right: 10px;
  }
</style>
